"""
内容:将购买商品封装成一个类
作者:Zhou
"""

#引入
from ECshop.common.base import create_browser,Base,create_browser_op
import time

class PageInventory01(Base):
    #属性
    url='http://localhost:8080/ecshop/user.php'
    first=('link text','首页')
    camera=("xpath",("//img[@src='images/201605/thumb_img/72_thumb_G_1462956048008.jpg']"))
    buy=('xpath',("//img[@src='themes/default/images/buybtn1.png']"))
    pay=('xpath',("//img[@src='themes/default/images/checkout.gif']"))
    all_price=("xpath","//div[@class='textInfo']/form/ul/li[5]/dd/font")
    first1=('link text','首页')
    camera1=("xpath",("//img[@src='images/201605/thumb_img/72_thumb_G_1462956048008.jpg']"))
    number=("xpath","//li[@class='clearfix']/dd[2]")
    put_in = ('xpath', ("//input[@src='themes/default/images/bnt_subOrder.gif']"))
    #方法
    #打开网页
    def page_inventory_web(self):
        self.base_open_web(self.url)
    #点击首页
    def page_inventory_first(self):
        self.base_click(self.first)
    #点击智能相机
    def page_inventory_camera(self):
        self.base_click(self.camera)
        time.sleep(2)
    #立即购买
    def page_inventory_buy(self):
        self.base_click(self.buy)
    #立即结算
    def page_inventory_pay(self):
        self.base_click(self.pay)
    #立即提交
    def page_inventory_in_put(self):
        self.base_click(self.put_in)
    #返回首页
    def page_inventory_firest1(self):
        self.base_click(self.first1)
    #点击智能相机
    def page_inventory_camera1(self):
        self.base_click(self.camera1)
        time.sleep(2)
    #获取库存数量
    def page_inventory_number(self):
        result=self.base_get_text(self.number)
        return result
    #关闭网页
    def page_inventory_quit(self):
        self.base_quit()

if __name__ == '__main__':
    pi1=PageInventory01(create_browser_op(r'C:\Users\lenovo\AppData\Local\Google\Chrome\User Data'))
    pi1.page_inventory_web()
    pi1.page_inventory_first()
    pi1.page_inventory_camera()
    pi1.page_inventory_buy()
    pi1.page_inventory_pay()
    pi1.page_inventory_firest1()
    pi1.page_inventory_camera1()
    print(pi1.page_inventory_number())